#!/usr/bin/python
import os
import cgi
import cgitb
from Cookie import SimpleCookie
from pygallib import userlib
from pygallib import usersession
from pygallib.usersession import LoginError
from pygallib.usersession import LogoutError
from pygallib import layoutlib

cgitb.enable()

try:
  usersession.logout()
  logout_success = True
except LogoutError as logout_error:
  logout_success = False

headers = {}
headers["Content-type"] = "text/html"
# Delete session cookie
if logout_success:
  headers["Set-Cookie"] = "pygallery_sid=; Expires=Fri, 2-Jan-1970 00:00:01 GMT"
layoutlib.print_http_headers(headers)
layoutlib.print_page_open("PyGallery - Login")
print("<body>")

menu = []
menu.append(("Home", "gallery.cgi"))
layoutlib.print_page_header(menu)
print('<div id="page_body">')

if logout_success:
  print("<p>Logout successful!</p>")
else:
  print("<p>Logout failure.</p>")
  print(logout_error.reason)

print('</div>')
layoutlib.print_page_close()
